options compress=YES;
libname manasi ''; 

* COLLAPSE DATA SET TO GET ONE OBSERVATION PER BENEFICIARY;

* SORT RECORDS BY HUN AND DATE ESTABLISHED;
proc sort data=manasi.kids_ssr_full_prep2 out=manasi.sortkids_ssr_full noduplicates;
	by hun estpd;
run;

* COLLAPSE DATA SET; 
data manasi.kids_ssr_full_collapse1;
	set manasi.sortkids_ssr_full;
	by hun;
	
	dibdig = input(dibdig,4.0);
	dibdig2 = input(dibdig2,4.0);

	* Create variables for diagnosis type, termination reason, permanent indicator;
	retain 
	n_diag1ever_none n_diag1ever_infec n_diag1ever_neo n_diag1ever_endo 
	n_diag1ever_blood n_diag1ever_mental n_diag1ever_nerv n_diag1ever_sense 
	n_diag1ever_circ n_diag1ever_resp n_diag1ever_dig n_diag1ever_gu
	n_diag1ever_preg n_diag1ever_skin n_diag1ever_musc n_diag1ever_cong 
	n_diag1ever_nat n_diag1ever_ill n_diag1ever_inj
	n_diag2ever_none n_diag2ever_infec n_diag2ever_neo n_diag2ever_endo 
	n_diag2ever_blood n_diag2ever_mental n_diag2ever_nerv n_diag2ever_sense 
	n_diag2ever_circ n_diag2ever_resp n_diag2ever_dig n_diag2ever_gu
	n_diag2ever_preg n_diag2ever_skin n_diag2ever_musc n_diag2ever_cong 
	n_diag2ever_nat n_diag2ever_ill n_diag2ever_inj
	n_diag_perm
	n_term18ever_N01 n_term18ever_N02 n_term18ever_N03 n_term18ever_N04 n_term18ever_N05
	n_term18ever_N06 n_term18ever_N07 n_term18ever_N08 n_term18ever_N09 n_term18ever_N10
	n_term18ever_N11 n_term18ever_N12 n_term18ever_N13 n_term18ever_N14 n_term18ever_N15
	n_term18ever_N16 n_term18ever_N17 n_term18ever_N18 n_term18ever_N19 n_term18ever_N20
	n_term18ever_N22 n_term18ever_N23 n_term18ever_N24 n_term18ever_N25 n_term18ever_N27
	n_term18ever_N30 n_term18ever_N31 n_term18ever_N32 n_term18ever_N33 n_term18ever_N34
	n_term18ever_N35 n_term18ever_N36 n_term18ever_N37 n_term18ever_N38 n_term18ever_N39
	n_term18ever_N40 n_term18ever_N41 n_term18ever_N42 n_term18ever_N43 n_term18ever_N44
	n_term18ever_N45 n_term18ever_N46 n_term18ever_N47 n_term18ever_N48 n_term18ever_N49
	n_term18ever_N50 n_term18ever_N51 n_term18ever_N52 n_term18ever_N53 n_term18ever_N54
	n_term18ever_P01 
	n_term18ever_S01 n_term18ever_S04 n_term18ever_S05 n_term18ever_S06 n_term18ever_S07 
	n_term18ever_S08 n_term18ever_S09 n_term18ever_S10 n_term18ever_S20 n_term18ever_S21 
	n_term18ever_S90 n_term18ever_S91 
	n_term18ever_H10 n_term18ever_H20 n_term18ever_H30 n_term18ever_H40 n_term18ever_H50
	n_term18ever_H60 n_term18ever_H70 n_term18ever_H80 n_term18ever_H90
	n_term18ever_M01 n_term18ever_M02
	n_fedpaylife n_statpaylife n_combpaylife n_paymonlife
	n_fedpay18 n_statpay18 n_combpay18 n_paymon18
	n_cdrunfav_life n_cdrunfav_18
	n_removed_life n_removed_18
	n_paymon_1983-n_paymon_2012 n_combpay_1983-n_combpay_2012
	n_cdrunfavyr_1991-n_cdrunfavyr_2012
	n_N01unfavyr_1991-n_N01unfavyr_2012
	n_N04unfavyr_1991-n_N04unfavyr_2012
	n_N20unfavyr_1991-n_N20unfavyr_2012
	n_N40unfavyr_1991-n_N40unfavyr_2012
	n_N43unfavyr_1991-n_N43unfavyr_2012
	n_N44unfavyr_1991-n_N44unfavyr_2012
	n_S06unfavyr_1991-n_S06unfavyr_2012
	n_M02unfavyr_1991-n_M02unfavyr_2012;

	%macro diag(type,no);
		n_diag&no.ever_&type.=0;
	%mend diag;

	%macro term(code);
		n_term18ever_&code.=0;
	%mend term;

	if first.hun then 
	do;
		%diag(none,1); %diag(infec,1); %diag(neo,1); %diag(endo,1); %diag(blood,1); %diag(mental,1);
		%diag(nerv,1); %diag(sense,1); %diag(circ,1); %diag(resp,1); %diag(dig,1); %diag(gu,1);
		%diag(preg,1); %diag(skin,1); %diag(musc,1); %diag(cong,1); %diag(nat,1); %diag(ill,1); %diag(inj,1);
		%diag(none,2); %diag(infec,2); %diag(neo,2); %diag(endo,2); %diag(blood,2); %diag(mental,2);
		%diag(nerv,2); %diag(sense,2); %diag(circ,2); %diag(resp,2); %diag(dig,2); %diag(gu,2);
		%diag(preg,2); %diag(skin,2); %diag(musc,2); %diag(cong,2); %diag(nat,2); %diag(ill,2); %diag(inj,2);
		n_diag_perm=0;
		%term(N01); %term(N02); %term(N03); %term(N04); %term(N05); %term(N06); %term(N07); %term(N08);
		%term(N09); %term(N10); %term(N11); %term(N12); %term(N13); %term(N14); %term(N15); %term(N16);
		%term(N17); %term(N18); %term(N19); %term(N20); %term(N22); %term(N23); %term(N24); %term(N25);
		%term(N27); %term(N30); %term(N31); %term(N32); %term(N33); %term(N34); %term(N35); %term(N36);
		%term(N37); %term(N38); %term(N39); %term(N40); %term(N41); %term(N42); %term(N43); %term(N44);
		%term(N45); %term(N46); %term(N47); %term(N48); %term(N49); %term(N50); %term(N51); %term(N52);
		%term(N53); %term(N54);
		%term(P01); 
		%term(S01); %term(S04); %term(S05); %term(S06); %term(S07); %term(S08); %term(S09); %term(S10);
		%term(S20); %term(S21); %term(S90); %term(S91);
		%term(H10); %term(H20); %term(H30); %term(H40); %term(H50); %term(H60); %term(H70); %term(H80);
		%term(H90);
		%term(M01); %term(M02);
		n_fedpaylife=0; n_fedpay18=0;
		n_statpaylife=0; n_statpay18=0;
		n_combpaylife=0; n_combpay18=0;
		n_paymonlife=0; n_paymon18=0;
		n_cdrunfav_life=0; n_cdrunfav_18=0;
		n_removed_life=0; n_removed_18=0;

		n_paymon_1983=0; n_paymon_1984=0; n_paymon_1985=0; n_paymon_1986=0;
		n_paymon_1987=0; n_paymon_1988=0; n_paymon_1989=0; n_paymon_1990=0;
		n_paymon_1991=0; n_paymon_1992=0; n_paymon_1993=0; n_paymon_1994=0;
		n_paymon_1995=0; n_paymon_1996=0; n_paymon_1997=0; n_paymon_1998=0;
		n_paymon_1999=0; n_paymon_2000=0; n_paymon_2001=0; n_paymon_2002=0;
		n_paymon_2003=0; n_paymon_2004=0; n_paymon_2005=0; n_paymon_2006=0;
		n_paymon_2007=0; n_paymon_2008=0; n_paymon_2009=0; n_paymon_2010=0;
		n_paymon_2011=0; n_paymon_2012=0;

		n_combpay_1983=0; n_combpay_1984=0; n_combpay_1985=0; n_combpay_1986=0;
		n_combpay_1987=0; n_combpay_1988=0; n_combpay_1989=0; n_combpay_1990=0;
		n_combpay_1991=0; n_combpay_1992=0; n_combpay_1993=0; n_combpay_1994=0;
		n_combpay_1995=0; n_combpay_1996=0; n_combpay_1997=0; n_combpay_1998=0;
		n_combpay_1999=0; n_combpay_2000=0; n_combpay_2001=0; n_combpay_2002=0;
		n_combpay_2003=0; n_combpay_2004=0; n_combpay_2005=0; n_combpay_2006=0;
		n_combpay_2007=0; n_combpay_2008=0; n_combpay_2009=0; n_combpay_2010=0;
		n_combpay_2011=0; n_combpay_2012=0;

		n_cdrunfavyr_1991=0; n_cdrunfavyr_1992=0; n_cdrunfavyr_1993=0; 
		n_cdrunfavyr_1994=0; n_cdrunfavyr_1995=0; n_cdrunfavyr_1996=0; n_cdrunfavyr_1997=0; 
		n_cdrunfavyr_1998=0; n_cdrunfavyr_1999=0; n_cdrunfavyr_2000=0; n_cdrunfavyr_2001=0; 
		n_cdrunfavyr_2002=0; n_cdrunfavyr_2003=0; n_cdrunfavyr_2004=0; n_cdrunfavyr_2005=0; 
		n_cdrunfavyr_2006=0; n_cdrunfavyr_2007=0; n_cdrunfavyr_2008=0; n_cdrunfavyr_2009=0;
		n_cdrunfavyr_2010=0; n_cdrunfavyr_2011=0; n_cdrunfavyr_2012=0; 

		n_N01unfavyr_1991=0; n_N01unfavyr_1992=0; n_N01unfavyr_1993=0; 
		n_N01unfavyr_1994=0; n_N01unfavyr_1995=0; n_N01unfavyr_1996=0; n_N01unfavyr_1997=0; 
		n_N01unfavyr_1998=0; n_N01unfavyr_1999=0; n_N01unfavyr_2000=0; n_N01unfavyr_2001=0; 
		n_N01unfavyr_2002=0; n_N01unfavyr_2003=0; n_N01unfavyr_2004=0; n_N01unfavyr_2005=0; 
		n_N01unfavyr_2006=0; n_N01unfavyr_2007=0; n_N01unfavyr_2008=0; n_N01unfavyr_2009=0;
		n_N01unfavyr_2010=0; n_N01unfavyr_2011=0; n_N01unfavyr_2012=0; 

		n_N04unfavyr_1991=0; n_N04unfavyr_1992=0; n_N04unfavyr_1993=0; 
		n_N04unfavyr_1994=0; n_N04unfavyr_1995=0; n_N04unfavyr_1996=0; n_N04unfavyr_1997=0; 
		n_N04unfavyr_1998=0; n_N04unfavyr_1999=0; n_N04unfavyr_2000=0; n_N04unfavyr_2001=0; 
		n_N04unfavyr_2002=0; n_N04unfavyr_2003=0; n_N04unfavyr_2004=0; n_N04unfavyr_2005=0; 
		n_N04unfavyr_2006=0; n_N04unfavyr_2007=0; n_N04unfavyr_2008=0; n_N04unfavyr_2009=0;
		n_N04unfavyr_2010=0; n_N04unfavyr_2011=0; n_N04unfavyr_2012=0; 

		n_N20unfavyr_1991=0; n_N20unfavyr_1992=0; n_N20unfavyr_1993=0; 
		n_N20unfavyr_1994=0; n_N20unfavyr_1995=0; n_N20unfavyr_1996=0; n_N20unfavyr_1997=0; 
		n_N20unfavyr_1998=0; n_N20unfavyr_1999=0; n_N20unfavyr_2000=0; n_N20unfavyr_2001=0; 
		n_N20unfavyr_2002=0; n_N20unfavyr_2003=0; n_N20unfavyr_2004=0; n_N20unfavyr_2005=0; 
		n_N20unfavyr_2006=0; n_N20unfavyr_2007=0; n_N20unfavyr_2008=0; n_N20unfavyr_2009=0;
		n_N20unfavyr_2010=0; n_N20unfavyr_2011=0; n_N20unfavyr_2012=0; 

		n_N40unfavyr_1991=0; n_N40unfavyr_1992=0; n_N40unfavyr_1993=0; 
		n_N40unfavyr_1994=0; n_N40unfavyr_1995=0; n_N40unfavyr_1996=0; n_N40unfavyr_1997=0; 
		n_N40unfavyr_1998=0; n_N40unfavyr_1999=0; n_N40unfavyr_2000=0; n_N40unfavyr_2001=0; 
		n_N40unfavyr_2002=0; n_N40unfavyr_2003=0; n_N40unfavyr_2004=0; n_N40unfavyr_2005=0; 
		n_N40unfavyr_2006=0; n_N40unfavyr_2007=0; n_N40unfavyr_2008=0; n_N40unfavyr_2009=0;
		n_N40unfavyr_2010=0; n_N40unfavyr_2011=0; n_N40unfavyr_2012=0; 

		n_N43unfavyr_1991=0; n_N43unfavyr_1992=0; n_N43unfavyr_1993=0; 
		n_N43unfavyr_1994=0; n_N43unfavyr_1995=0; n_N43unfavyr_1996=0; n_N43unfavyr_1997=0; 
		n_N43unfavyr_1998=0; n_N43unfavyr_1999=0; n_N43unfavyr_2000=0; n_N43unfavyr_2001=0; 
		n_N43unfavyr_2002=0; n_N43unfavyr_2003=0; n_N43unfavyr_2004=0; n_N43unfavyr_2005=0; 
		n_N43unfavyr_2006=0; n_N43unfavyr_2007=0; n_N43unfavyr_2008=0; n_N43unfavyr_2009=0;
		n_N43unfavyr_2010=0; n_N43unfavyr_2011=0; n_N43unfavyr_2012=0; 

		n_N44unfavyr_1991=0; n_N44unfavyr_1992=0; n_N44unfavyr_1993=0; 
		n_N44unfavyr_1994=0; n_N44unfavyr_1995=0; n_N44unfavyr_1996=0; n_N44unfavyr_1997=0; 
		n_N44unfavyr_1998=0; n_N44unfavyr_1999=0; n_N44unfavyr_2000=0; n_N44unfavyr_2001=0; 
		n_N44unfavyr_2002=0; n_N44unfavyr_2003=0; n_N44unfavyr_2004=0; n_N44unfavyr_2005=0; 
		n_N44unfavyr_2006=0; n_N44unfavyr_2007=0; n_N44unfavyr_2008=0; n_N44unfavyr_2009=0;
		n_N44unfavyr_2010=0; n_N44unfavyr_2011=0; n_N44unfavyr_2012=0; 

		n_S06unfavyr_1991=0; n_S06unfavyr_1992=0; n_S06unfavyr_1993=0; 
		n_S06unfavyr_1994=0; n_S06unfavyr_1995=0; n_S06unfavyr_1996=0; n_S06unfavyr_1997=0; 
		n_S06unfavyr_1998=0; n_S06unfavyr_1999=0; n_S06unfavyr_2000=0; n_S06unfavyr_2001=0; 
		n_S06unfavyr_2002=0; n_S06unfavyr_2003=0; n_S06unfavyr_2004=0; n_S06unfavyr_2005=0; 
		n_S06unfavyr_2006=0; n_S06unfavyr_2007=0; n_S06unfavyr_2008=0; n_S06unfavyr_2009=0;
		n_S06unfavyr_2010=0; n_S06unfavyr_2011=0; n_S06unfavyr_2012=0; 

		n_M02unfavyr_1991=0; n_M02unfavyr_1992=0; n_M02unfavyr_1993=0; 
		n_M02unfavyr_1994=0; n_M02unfavyr_1995=0; n_M02unfavyr_1996=0; n_M02unfavyr_1997=0; 
		n_M02unfavyr_1998=0; n_M02unfavyr_1999=0; n_M02unfavyr_2000=0; n_M02unfavyr_2001=0; 
		n_M02unfavyr_2002=0; n_M02unfavyr_2003=0; n_M02unfavyr_2004=0; n_M02unfavyr_2005=0; 
		n_M02unfavyr_2006=0; n_M02unfavyr_2007=0; n_M02unfavyr_2008=0; n_M02unfavyr_2009=0;
		n_M02unfavyr_2010=0; n_M02unfavyr_2011=0; n_M02unfavyr_2012=0; 
	end;

	%macro diagever(type,no);
		if (n_diag&no._&type.=1) then n_diag&no.ever_&type.=1;
	%mend diagever;

	%diagever(none,1); %diagever(infec,1); %diagever(neo,1); %diagever(endo,1); %diagever(blood,1); %diagever(mental,1);
	%diagever(nerv,1); %diagever(sense,1); %diagever(circ,1); %diagever(resp,1); %diagever(dig,1); %diagever(gu,1);
	%diagever(preg,1); %diagever(skin,1); %diagever(musc,1); %diagever(cong,1); %diagever(nat,1); %diagever(ill,1); %diagever(inj,1);
	%diagever(none,2); %diagever(infec,2); %diagever(neo,2); %diagever(endo,2); %diagever(blood,2); %diagever(mental,2);
	%diagever(nerv,2); %diagever(sense,2); %diagever(circ,2); %diagever(resp,2); %diagever(dig,2); %diagever(gu,2);
	%diagever(preg,2); %diagever(skin,2); %diagever(musc,2); %diagever(cong,2); %diagever(nat,2); %diagever(ill,2); %diagever(inj,2);

	%macro term18ever(code);
		if (n_term18_&code.=1) then n_term18ever_&code.=1;
	%mend term18ever;

	%term18ever(N01); %term18ever(N02); %term18ever(N03); %term18ever(N04); %term18ever(N05); %term18ever(N06); %term18ever(N07); %term18ever(N08);
	%term18ever(N09); %term18ever(N10); %term18ever(N11); %term18ever(N12); %term18ever(N13); %term18ever(N14); %term18ever(N15); %term18ever(N16);
	%term18ever(N17); %term18ever(N18); %term18ever(N19); %term18ever(N20); %term18ever(N22); %term18ever(N23); %term18ever(N24); %term18ever(N25);
	%term18ever(N27); %term18ever(N30); %term18ever(N31); %term18ever(N32); %term18ever(N33); %term18ever(N34); %term18ever(N35); %term18ever(N36);
	%term18ever(N37); %term18ever(N38); %term18ever(N39); %term18ever(N40); %term18ever(N41); %term18ever(N42); %term18ever(N43); %term18ever(N44);
	%term18ever(N45); %term18ever(N46); %term18ever(N47); %term18ever(N48); %term18ever(N49); %term18ever(N50); %term18ever(N51); %term18ever(N52);
	%term18ever(N53); %term18ever(N54);
	%term18ever(P01); 
	%term18ever(S01); %term18ever(S04); %term18ever(S05); %term18ever(S06); %term18ever(S07); %term18ever(S08); %term18ever(S09); %term18ever(S10);
	%term18ever(S20); %term18ever(S21); %term18ever(S90); %term18ever(S91);
	%term18ever(H10); %term18ever(H20); %term18ever(H30); %term18ever(H40); %term18ever(H50); %term18ever(H60); %term18ever(H70); %term18ever(H80);
	%term18ever(H90);
	%term18ever(M01); %term18ever(M02);	

	if (perm_ind=1) then n_diag_perm=1;
	
	n_fedpaylife = n_fedpaylife + n_fedpaytot;
	n_statpaylife = n_statpaylife + n_statpaytot;
	n_combpaylife = n_combpaylife + n_combpaytot;
	n_paymonlife = n_paymonlife + n_paymontot;

	n_fedpay18 = n_fedpay18 + n_fedpaytot18;
	n_statpay18 = n_statpay18 + n_statpaytot18;
	n_combpay18 = n_combpay18 + n_combpaytot18;
	n_paymon18 = n_paymon18 + n_paymontot18;
	
	if (n_cdr_unfav=1) then n_cdrunfav_life=1;
	if (n_cdr_unfav18=1) then n_cdrunfav_18=1;
	if (n_remove=1) then n_removed_life=1;
	if (n_remove18=1) then n_removed_18=1;
	
	%macro paymon(yr);
		n_paymon_&yr. = n_paymon_&yr. + n_paymonyr_&yr.;
	%mend paymon;
	
	%paymon(1983); %paymon(1984); %paymon(1985); %paymon(1986); %paymon(1987); 
	%paymon(1988); %paymon(1989); %paymon(1990); %paymon(1991); %paymon(1992);
	%paymon(1993); %paymon(1994); %paymon(1995); %paymon(1996); %paymon(1997);
	%paymon(1998); %paymon(1999); %paymon(2000); %paymon(2001); %paymon(2002);
	%paymon(2003); %paymon(2004); %paymon(2005); %paymon(2006); %paymon(2007);
	%paymon(2008); %paymon(2009); %paymon(2010); %paymon(2011); %paymon(2012);

	%macro combpay(yr);
		n_combpay_&yr. = n_combpay_&yr. + n_combpayyr_&yr.;
	%mend combpay;
	
	%combpay(1983); %combpay(1984); %combpay(1985); %combpay(1986); %combpay(1987); 
	%combpay(1988); %combpay(1989); %combpay(1990); %combpay(1991); %combpay(1992);
	%combpay(1993); %combpay(1994); %combpay(1995); %combpay(1996); %combpay(1997);
	%combpay(1998); %combpay(1999); %combpay(2000); %combpay(2001); %combpay(2002);
	%combpay(2003); %combpay(2004); %combpay(2005); %combpay(2006); %combpay(2007);
	%combpay(2008); %combpay(2009); %combpay(2010); %combpay(2011); %combpay(2012);

	if (n_cdrunfavyear_1991=1) then n_cdrunfavyr_1991=1;
	if (n_cdrunfavyear_1992=1) then n_cdrunfavyr_1992=1;
	if (n_cdrunfavyear_1993=1) then n_cdrunfavyr_1993=1;
	if (n_cdrunfavyear_1994=1) then n_cdrunfavyr_1994=1;
	if (n_cdrunfavyear_1995=1) then n_cdrunfavyr_1995=1;
	if (n_cdrunfavyear_1996=1) then n_cdrunfavyr_1996=1;
	if (n_cdrunfavyear_1997=1) then n_cdrunfavyr_1997=1;
	if (n_cdrunfavyear_1998=1) then n_cdrunfavyr_1998=1;
	if (n_cdrunfavyear_1999=1) then n_cdrunfavyr_1999=1;
	if (n_cdrunfavyear_2000=1) then n_cdrunfavyr_2000=1;
	if (n_cdrunfavyear_2001=1) then n_cdrunfavyr_2001=1;
	if (n_cdrunfavyear_2002=1) then n_cdrunfavyr_2002=1;
	if (n_cdrunfavyear_2003=1) then n_cdrunfavyr_2003=1;
	if (n_cdrunfavyear_2004=1) then n_cdrunfavyr_2004=1;
	if (n_cdrunfavyear_2005=1) then n_cdrunfavyr_2005=1;
	if (n_cdrunfavyear_2006=1) then n_cdrunfavyr_2006=1;
	if (n_cdrunfavyear_2007=1) then n_cdrunfavyr_2007=1;
	if (n_cdrunfavyear_2008=1) then n_cdrunfavyr_2008=1;
	if (n_cdrunfavyear_2009=1) then n_cdrunfavyr_2009=1;
	if (n_cdrunfavyear_2010=1) then n_cdrunfavyr_2010=1;
	if (n_cdrunfavyear_2011=1) then n_cdrunfavyr_2011=1;
	if (n_cdrunfavyear_2012=1) then n_cdrunfavyr_2012=1;

	if (n_N01unfavyear_1991=1) then n_N01unfavyr_1991=1;
	if (n_N01unfavyear_1992=1) then n_N01unfavyr_1992=1;
	if (n_N01unfavyear_1993=1) then n_N01unfavyr_1993=1;
	if (n_N01unfavyear_1994=1) then n_N01unfavyr_1994=1;
	if (n_N01unfavyear_1995=1) then n_N01unfavyr_1995=1;
	if (n_N01unfavyear_1996=1) then n_N01unfavyr_1996=1;
	if (n_N01unfavyear_1997=1) then n_N01unfavyr_1997=1;
	if (n_N01unfavyear_1998=1) then n_N01unfavyr_1998=1;
	if (n_N01unfavyear_1999=1) then n_N01unfavyr_1999=1;
	if (n_N01unfavyear_2000=1) then n_N01unfavyr_2000=1;
	if (n_N01unfavyear_2001=1) then n_N01unfavyr_2001=1;
	if (n_N01unfavyear_2002=1) then n_N01unfavyr_2002=1;
	if (n_N01unfavyear_2003=1) then n_N01unfavyr_2003=1;
	if (n_N01unfavyear_2004=1) then n_N01unfavyr_2004=1;
	if (n_N01unfavyear_2005=1) then n_N01unfavyr_2005=1;
	if (n_N01unfavyear_2006=1) then n_N01unfavyr_2006=1;
	if (n_N01unfavyear_2007=1) then n_N01unfavyr_2007=1;
	if (n_N01unfavyear_2008=1) then n_N01unfavyr_2008=1;
	if (n_N01unfavyear_2009=1) then n_N01unfavyr_2009=1;
	if (n_N01unfavyear_2010=1) then n_N01unfavyr_2010=1;
	if (n_N01unfavyear_2011=1) then n_N01unfavyr_2011=1;
	if (n_N01unfavyear_2012=1) then n_N01unfavyr_2012=1;

	if (n_N04unfavyear_1991=1) then n_N04unfavyr_1991=1;
	if (n_N04unfavyear_1992=1) then n_N04unfavyr_1992=1;
	if (n_N04unfavyear_1993=1) then n_N04unfavyr_1993=1;
	if (n_N04unfavyear_1994=1) then n_N04unfavyr_1994=1;
	if (n_N04unfavyear_1995=1) then n_N04unfavyr_1995=1;
	if (n_N04unfavyear_1996=1) then n_N04unfavyr_1996=1;
	if (n_N04unfavyear_1997=1) then n_N04unfavyr_1997=1;
	if (n_N04unfavyear_1998=1) then n_N04unfavyr_1998=1;
	if (n_N04unfavyear_1999=1) then n_N04unfavyr_1999=1;
	if (n_N04unfavyear_2000=1) then n_N04unfavyr_2000=1;
	if (n_N04unfavyear_2001=1) then n_N04unfavyr_2001=1;
	if (n_N04unfavyear_2002=1) then n_N04unfavyr_2002=1;
	if (n_N04unfavyear_2003=1) then n_N04unfavyr_2003=1;
	if (n_N04unfavyear_2004=1) then n_N04unfavyr_2004=1;
	if (n_N04unfavyear_2005=1) then n_N04unfavyr_2005=1;
	if (n_N04unfavyear_2006=1) then n_N04unfavyr_2006=1;
	if (n_N04unfavyear_2007=1) then n_N04unfavyr_2007=1;
	if (n_N04unfavyear_2008=1) then n_N04unfavyr_2008=1;
	if (n_N04unfavyear_2009=1) then n_N04unfavyr_2009=1;
	if (n_N04unfavyear_2010=1) then n_N04unfavyr_2010=1;
	if (n_N04unfavyear_2011=1) then n_N04unfavyr_2011=1;
	if (n_N04unfavyear_2012=1) then n_N04unfavyr_2012=1;

	if (n_N20unfavyear_1991=1) then n_N20unfavyr_1991=1;
	if (n_N20unfavyear_1992=1) then n_N20unfavyr_1992=1;
	if (n_N20unfavyear_1993=1) then n_N20unfavyr_1993=1;
	if (n_N20unfavyear_1994=1) then n_N20unfavyr_1994=1;
	if (n_N20unfavyear_1995=1) then n_N20unfavyr_1995=1;
	if (n_N20unfavyear_1996=1) then n_N20unfavyr_1996=1;
	if (n_N20unfavyear_1997=1) then n_N20unfavyr_1997=1;
	if (n_N20unfavyear_1998=1) then n_N20unfavyr_1998=1;
	if (n_N20unfavyear_1999=1) then n_N20unfavyr_1999=1;
	if (n_N20unfavyear_2000=1) then n_N20unfavyr_2000=1;
	if (n_N20unfavyear_2001=1) then n_N20unfavyr_2001=1;
	if (n_N20unfavyear_2002=1) then n_N20unfavyr_2002=1;
	if (n_N20unfavyear_2003=1) then n_N20unfavyr_2003=1;
	if (n_N20unfavyear_2004=1) then n_N20unfavyr_2004=1;
	if (n_N20unfavyear_2005=1) then n_N20unfavyr_2005=1;
	if (n_N20unfavyear_2006=1) then n_N20unfavyr_2006=1;
	if (n_N20unfavyear_2007=1) then n_N20unfavyr_2007=1;
	if (n_N20unfavyear_2008=1) then n_N20unfavyr_2008=1;
	if (n_N20unfavyear_2009=1) then n_N20unfavyr_2009=1;
	if (n_N20unfavyear_2010=1) then n_N20unfavyr_2010=1;
	if (n_N20unfavyear_2011=1) then n_N20unfavyr_2011=1;
	if (n_N20unfavyear_2012=1) then n_N20unfavyr_2012=1;

	if (n_N40unfavyear_1991=1) then n_N40unfavyr_1991=1;
	if (n_N40unfavyear_1992=1) then n_N40unfavyr_1992=1;
	if (n_N40unfavyear_1993=1) then n_N40unfavyr_1993=1;
	if (n_N40unfavyear_1994=1) then n_N40unfavyr_1994=1;
	if (n_N40unfavyear_1995=1) then n_N40unfavyr_1995=1;
	if (n_N40unfavyear_1996=1) then n_N40unfavyr_1996=1;
	if (n_N40unfavyear_1997=1) then n_N40unfavyr_1997=1;
	if (n_N40unfavyear_1998=1) then n_N40unfavyr_1998=1;
	if (n_N40unfavyear_1999=1) then n_N40unfavyr_1999=1;
	if (n_N40unfavyear_2000=1) then n_N40unfavyr_2000=1;
	if (n_N40unfavyear_2001=1) then n_N40unfavyr_2001=1;
	if (n_N40unfavyear_2002=1) then n_N40unfavyr_2002=1;
	if (n_N40unfavyear_2003=1) then n_N40unfavyr_2003=1;
	if (n_N40unfavyear_2004=1) then n_N40unfavyr_2004=1;
	if (n_N40unfavyear_2005=1) then n_N40unfavyr_2005=1;
	if (n_N40unfavyear_2006=1) then n_N40unfavyr_2006=1;
	if (n_N40unfavyear_2007=1) then n_N40unfavyr_2007=1;
	if (n_N40unfavyear_2008=1) then n_N40unfavyr_2008=1;
	if (n_N40unfavyear_2009=1) then n_N40unfavyr_2009=1;
	if (n_N40unfavyear_2010=1) then n_N40unfavyr_2010=1;
	if (n_N40unfavyear_2011=1) then n_N40unfavyr_2011=1;
	if (n_N40unfavyear_2012=1) then n_N40unfavyr_2012=1;

	if (n_N43unfavyear_1991=1) then n_N43unfavyr_1991=1;
	if (n_N43unfavyear_1992=1) then n_N43unfavyr_1992=1;
	if (n_N43unfavyear_1993=1) then n_N43unfavyr_1993=1;
	if (n_N43unfavyear_1994=1) then n_N43unfavyr_1994=1;
	if (n_N43unfavyear_1995=1) then n_N43unfavyr_1995=1;
	if (n_N43unfavyear_1996=1) then n_N43unfavyr_1996=1;
	if (n_N43unfavyear_1997=1) then n_N43unfavyr_1997=1;
	if (n_N43unfavyear_1998=1) then n_N43unfavyr_1998=1;
	if (n_N43unfavyear_1999=1) then n_N43unfavyr_1999=1;
	if (n_N43unfavyear_2000=1) then n_N43unfavyr_2000=1;
	if (n_N43unfavyear_2001=1) then n_N43unfavyr_2001=1;
	if (n_N43unfavyear_2002=1) then n_N43unfavyr_2002=1;
	if (n_N43unfavyear_2003=1) then n_N43unfavyr_2003=1;
	if (n_N43unfavyear_2004=1) then n_N43unfavyr_2004=1;
	if (n_N43unfavyear_2005=1) then n_N43unfavyr_2005=1;
	if (n_N43unfavyear_2006=1) then n_N43unfavyr_2006=1;
	if (n_N43unfavyear_2007=1) then n_N43unfavyr_2007=1;
	if (n_N43unfavyear_2008=1) then n_N43unfavyr_2008=1;
	if (n_N43unfavyear_2009=1) then n_N43unfavyr_2009=1;
	if (n_N43unfavyear_2010=1) then n_N43unfavyr_2010=1;
	if (n_N43unfavyear_2011=1) then n_N43unfavyr_2011=1;
	if (n_N43unfavyear_2012=1) then n_N43unfavyr_2012=1;

	if (n_N44unfavyear_1991=1) then n_N44unfavyr_1991=1;
	if (n_N44unfavyear_1992=1) then n_N44unfavyr_1992=1;
	if (n_N44unfavyear_1993=1) then n_N44unfavyr_1993=1;
	if (n_N44unfavyear_1994=1) then n_N44unfavyr_1994=1;
	if (n_N44unfavyear_1995=1) then n_N44unfavyr_1995=1;
	if (n_N44unfavyear_1996=1) then n_N44unfavyr_1996=1;
	if (n_N44unfavyear_1997=1) then n_N44unfavyr_1997=1;
	if (n_N44unfavyear_1998=1) then n_N44unfavyr_1998=1;
	if (n_N44unfavyear_1999=1) then n_N44unfavyr_1999=1;
	if (n_N44unfavyear_2000=1) then n_N44unfavyr_2000=1;
	if (n_N44unfavyear_2001=1) then n_N44unfavyr_2001=1;
	if (n_N44unfavyear_2002=1) then n_N44unfavyr_2002=1;
	if (n_N44unfavyear_2003=1) then n_N44unfavyr_2003=1;
	if (n_N44unfavyear_2004=1) then n_N44unfavyr_2004=1;
	if (n_N44unfavyear_2005=1) then n_N44unfavyr_2005=1;
	if (n_N44unfavyear_2006=1) then n_N44unfavyr_2006=1;
	if (n_N44unfavyear_2007=1) then n_N44unfavyr_2007=1;
	if (n_N44unfavyear_2008=1) then n_N44unfavyr_2008=1;
	if (n_N44unfavyear_2009=1) then n_N44unfavyr_2009=1;
	if (n_N44unfavyear_2010=1) then n_N44unfavyr_2010=1;
	if (n_N44unfavyear_2011=1) then n_N44unfavyr_2011=1;
	if (n_N44unfavyear_2012=1) then n_N44unfavyr_2012=1;

	if (n_S06unfavyear_1991=1) then n_S06unfavyr_1991=1;
	if (n_S06unfavyear_1992=1) then n_S06unfavyr_1992=1;
	if (n_S06unfavyear_1993=1) then n_S06unfavyr_1993=1;
	if (n_S06unfavyear_1994=1) then n_S06unfavyr_1994=1;
	if (n_S06unfavyear_1995=1) then n_S06unfavyr_1995=1;
	if (n_S06unfavyear_1996=1) then n_S06unfavyr_1996=1;
	if (n_S06unfavyear_1997=1) then n_S06unfavyr_1997=1;
	if (n_S06unfavyear_1998=1) then n_S06unfavyr_1998=1;
	if (n_S06unfavyear_1999=1) then n_S06unfavyr_1999=1;
	if (n_S06unfavyear_2000=1) then n_S06unfavyr_2000=1;
	if (n_S06unfavyear_2001=1) then n_S06unfavyr_2001=1;
	if (n_S06unfavyear_2002=1) then n_S06unfavyr_2002=1;
	if (n_S06unfavyear_2003=1) then n_S06unfavyr_2003=1;
	if (n_S06unfavyear_2004=1) then n_S06unfavyr_2004=1;
	if (n_S06unfavyear_2005=1) then n_S06unfavyr_2005=1;
	if (n_S06unfavyear_2006=1) then n_S06unfavyr_2006=1;
	if (n_S06unfavyear_2007=1) then n_S06unfavyr_2007=1;
	if (n_S06unfavyear_2008=1) then n_S06unfavyr_2008=1;
	if (n_S06unfavyear_2009=1) then n_S06unfavyr_2009=1;
	if (n_S06unfavyear_2010=1) then n_S06unfavyr_2010=1;
	if (n_S06unfavyear_2011=1) then n_S06unfavyr_2011=1;
	if (n_S06unfavyear_2012=1) then n_S06unfavyr_2012=1;

	if (n_M02unfavyear_1990=1) then n_M02unfavyr_1990=1;
	if (n_M02unfavyear_1991=1) then n_M02unfavyr_1991=1;
	if (n_M02unfavyear_1992=1) then n_M02unfavyr_1992=1;
	if (n_M02unfavyear_1993=1) then n_M02unfavyr_1993=1;
	if (n_M02unfavyear_1994=1) then n_M02unfavyr_1994=1;
	if (n_M02unfavyear_1995=1) then n_M02unfavyr_1995=1;
	if (n_M02unfavyear_1996=1) then n_M02unfavyr_1996=1;
	if (n_M02unfavyear_1997=1) then n_M02unfavyr_1997=1;
	if (n_M02unfavyear_1998=1) then n_M02unfavyr_1998=1;
	if (n_M02unfavyear_1999=1) then n_M02unfavyr_1999=1;
	if (n_M02unfavyear_2000=1) then n_M02unfavyr_2000=1;
	if (n_M02unfavyear_2001=1) then n_M02unfavyr_2001=1;
	if (n_M02unfavyear_2002=1) then n_M02unfavyr_2002=1;
	if (n_M02unfavyear_2003=1) then n_M02unfavyr_2003=1;
	if (n_M02unfavyear_2004=1) then n_M02unfavyr_2004=1;
	if (n_M02unfavyear_2005=1) then n_M02unfavyr_2005=1;
	if (n_M02unfavyear_2006=1) then n_M02unfavyr_2006=1;
	if (n_M02unfavyear_2007=1) then n_M02unfavyr_2007=1;
	if (n_M02unfavyear_2008=1) then n_M02unfavyr_2008=1;
	if (n_M02unfavyear_2009=1) then n_M02unfavyr_2009=1;
	if (n_M02unfavyear_2010=1) then n_M02unfavyr_2010=1;
	if (n_M02unfavyear_2011=1) then n_M02unfavyr_2011=1;
	if (n_M02unfavyear_2012=1) then n_M02unfavyr_2012=1;
	
	if last.hun then
	do; 
		output;
	end;

	keep hun pan 
	estpd n_estpd_yr n_estpd_mo n_estpd_day n_estpd_age n_estpd_char n_estpd_num
	dob dobyy n_dobmm n_dobdd n_age18_yr n_age18_mo n_age18_day 
	sex dibmdr dibdig dibdig2 pdscc
	n_diag1ever_none n_diag1ever_infec n_diag1ever_neo n_diag1ever_endo 
	n_diag1ever_blood n_diag1ever_mental n_diag1ever_nerv n_diag1ever_sense 
	n_diag1ever_circ n_diag1ever_resp n_diag1ever_dig n_diag1ever_gu
	n_diag1ever_preg n_diag1ever_skin n_diag1ever_musc n_diag1ever_cong 
	n_diag1ever_nat n_diag1ever_ill n_diag1ever_inj
	n_diag2ever_none n_diag2ever_infec n_diag2ever_neo n_diag2ever_endo 
	n_diag2ever_blood n_diag2ever_mental n_diag2ever_nerv n_diag2ever_sense 
	n_diag2ever_circ n_diag2ever_resp n_diag2ever_dig n_diag2ever_gu
	n_diag2ever_preg n_diag2ever_skin n_diag2ever_musc n_diag2ever_cong 
	n_diag2ever_nat n_diag2ever_ill n_diag2ever_inj
	n_diag_perm
	n_term18ever_N01 n_term18ever_N02 n_term18ever_N03 n_term18ever_N04 n_term18ever_N05
	n_term18ever_N06 n_term18ever_N07 n_term18ever_N08 n_term18ever_N09 n_term18ever_N10
	n_term18ever_N11 n_term18ever_N12 n_term18ever_N13 n_term18ever_N14 n_term18ever_N15
	n_term18ever_N16 n_term18ever_N17 n_term18ever_N18 n_term18ever_N19 n_term18ever_N20
	n_term18ever_N22 n_term18ever_N23 n_term18ever_N24 n_term18ever_N25 n_term18ever_N27
	n_term18ever_N30 n_term18ever_N31 n_term18ever_N32 n_term18ever_N33 n_term18ever_N34
	n_term18ever_N35 n_term18ever_N36 n_term18ever_N37 n_term18ever_N38 n_term18ever_N39
	n_term18ever_N40 n_term18ever_N41 n_term18ever_N42 n_term18ever_N43 n_term18ever_N44
	n_term18ever_N45 n_term18ever_N46 n_term18ever_N47 n_term18ever_N48 n_term18ever_N49
	n_term18ever_N50 n_term18ever_N51 n_term18ever_N52 n_term18ever_N53 n_term18ever_N54
	n_term18ever_P01 
	n_term18ever_S01 n_term18ever_S04 n_term18ever_S05 n_term18ever_S06 n_term18ever_S07 
	n_term18ever_S08 n_term18ever_S09 n_term18ever_S10 n_term18ever_S20 n_term18ever_S21 
	n_term18ever_S90 n_term18ever_S91 
	n_term18ever_H10 n_term18ever_H20 n_term18ever_H30 n_term18ever_H40 n_term18ever_H50
	n_term18ever_H60 n_term18ever_H70 n_term18ever_H80 n_term18ever_H90
	n_term18ever_M01 n_term18ever_M02
	n_fedpaylife n_statpaylife n_combpaylife n_paymonlife
	n_fedpay18 n_statpay18 n_combpay18 n_paymon18
	n_cdrunfav_life n_cdrunfav_18
	n_removed_life n_removed_18
	n_paymon_1983-n_paymon_2012 n_combpay_1983-n_combpay_2012
	n_cdrunfavyr_1991-n_cdrunfavyr_2012
	n_N01unfavyr_1991-n_N01unfavyr_2012
	n_N04unfavyr_1991-n_N04unfavyr_2012
	n_N20unfavyr_1991-n_N20unfavyr_2012
	n_N40unfavyr_1991-n_N40unfavyr_2012
	n_N43unfavyr_1991-n_N43unfavyr_2012
	n_N44unfavyr_1991-n_N44unfavyr_2012
	n_S06unfavyr_1991-n_S06unfavyr_2012
	n_M02unfavyr_1991-n_M02unfavyr_2012;

	label n_fedpaylife='Federal SSI payments (lifetime)';
	label n_statpaylife='State SSI payments (lifetime)';
	label n_combpaylife='Combined SSI payments (lifetime)';
	label n_paymonlife='Months of SSI payment (lifetime)';
	label n_fedpay18='Federal SSI payments (up to 18)';
	label n_statpay18='State SSI payments (up to 18)';
	label n_combpay18='Combined SSI payments (up to 18)';
	label n_paymon18='Months of SSI payment (up to 18)';
	label n_cdrunfav_life='Unfavorable CDR in lifetime';
	label n_cdrunfav_18='Unfavorable CDR before age 18';
	label n_removed_life='Ever removed from SSI in lifetime';
	label n_removed_18='Ever removed from SSI before 18';
	label n_paymon_1983='No of payment months (actual) in 1983';
	label n_combpay_1983='Total combined payment (actual) in 1983';
run;

* DATE AND AGE OF LAST PAYMENT;
proc means noprint data=manasi.kids_ssr_full_prep2 nway;
	class hun;
	var n_lastage n_lastpay_yr n_payavg: ;
	output out=manasi.kids_ssr_full_collapse3 max= ;
run;

* AGE AND YEAR AT FIRST PAYMENT;
proc means noprint data=manasi.kids_ssr_full_prep2 nway;
	class hun;
	var n_firstage n_firstpay_yr awddte;
	output out=manasi.kids_ssr_full_collapse2 min= ;
run;


data manasi.kids_ssr_full_summ;
	merge 	manasi.kids_ssr_full_collapse1 manasi.kids_ssr_full_collapse2 
			manasi.kids_ssr_full_collapse3;
	by hun; 
run;
